require "Common/define"
require "Logic/Config"
require "Common/functions"
---@class ActiveManager
ActiveManager = ActiveManager or {};
local this = ActiveManager;
this._activityDrawType = 20;
this._activityCardTaskCfg = nil;

ActiveManager.sevenDayInfotab = {}; --七日登錄s
local activeEntranceTableData;
local activeListTableData;
this.isNeedShowPopUpTips = true;

function ActiveManager.initData()
    this.activeBeginTime = {};
    this.entranceList = {};
    this.activeEndTime = {};
    this.activeServerDataList = {};
    this.turntableActivityDataList = {};
    this.turntableTaskDataList = {};
    this.turntableRankDataList = {};
    this.activityExplorRankData = {};
    this.ecoBuffUtimeMap = {};
    this.activityExplorTaskData = {};
end

function ActiveManager.init()
    this.initData();
    activeEntranceTableData = G.dataTable["t_activityentrance"];
    activeListTableData = G.dataTable["t_activitylist"];
    this.timingUpdate();
    this.HourHeartbeat();
    CloseEvent(Config.EventType.Fresh_Level, this.FreshLevelInfo);
    CloseEvent(Config.EventType.VIPInfoUpdate, this.FreshLevelInfo);
    ListenEvent(Config.EventType.VIPInfoUpdate, this.FreshLevelInfo);
    ListenEvent(Config.EventType.Fresh_Level, this.FreshLevelInfo);
end

function ActiveManager.OnDestroy()
    for _, v in pairs(this.ecoBuffUtimeMap) do
        utimer.remove(v);
    end
    for _, v in pairs(this.activeBeginTime) do
        utimer.remove(v);
    end
    for _, v in pairs(this.activeEndTime) do
        utimer.remove(v);
    end
    if this.updateTime ~= nil then
        utimer.remove(this.updateTime);
    end
    if  this.updateHourTime ~= nil then
        utimer.remove(this.updateHourTime)
    end
    this.celebrationBigAwardData = nil
    this._activityCardTaskCfg = nil;
end

function ActiveManager.getActiveEntranceDataListByType(type)
    if type == nil then
        return this.entranceList or {};
    end
    return this.entranceList[tostring(type)] or {};
end

function ActiveManager.getActiveEntranceDataById(id)
    if id == nil then
        return this.entranceList or {};
    end
    for k, v in pairs(this.entranceList) do
        for key, value in pairs(v) do
            if value.activeId == id then
                return value;
            end
        end
    end
    return nil;
end

function ActiveManager.getActiveTableList(id)
    if id == nil then
        return activeListTableData or {};
    end
    return activeListTableData[tostring(id)];
end

function ActiveManager.getActiveServerDataList(id)
    if id == nil then
        return this.activeServerDataList or {};
    end
    return this.activeServerDataList[tostring(id)];
end

--处理接收的活动数据
function ActiveManager.resActiveServerData(data)
     for k, v in pairs(data) do
        v.activeId = v.activityId
        v.startTime = tonumber(tostring(v.startTime)) * 0.001;
        --卫峰的恶心需求，先临时在这写
        if 10501 == tonumber(v.activeId) then
            local globalOpenTime = 0;
            local globalCfg = G.dataTable["t_global"][tostring(453)];
            if globalCfg ~= nil then
                globalOpenTime = globalCfg.f_int_value;
            end
            v.startTime = v.startTime + (globalOpenTime * 24 * 3600);
        end
        v.endTime = tonumber(tostring(v.endTime)) * 0.001;  -- 活动挑战时间
        v.drawEndTime = v.endTime;     -- 活动真正结束时间 （和 v.endTime 时间一致，虽然可以随便用，但建议用 drawEndTime）
        if v.updateParam == 1 then
            if v.param ~= nil then
                v.param = decodeJsonStrToTabel(v.param);
            else
                v.param = {};
            end
        else
            local serverData = this.getActiveServerDataList(v.activeId);
            if serverData ~= nil then
                v.param = serverData.param;
            else
                v.param = {};
            end
        end
    end
    this.initAllActive(data);
end

--领取奖励返回
function ActiveManager.getFetchReward(data)
    logicMgr.HeroManager.showNewHero(function ()
        if data ~= nil then
            local rewards = {};
            for k,v in pairs(data) do
                local itemData = logicMgr.CostManager.getItemOrEquipDataByIdAndNum(v.itemModelId, v.num);
                if itemData ~= nil then
                    table.insert(rewards, itemData);
                end
            end
            if #rewards > 0 then
                ShowSpItemGetPanel(rewards, logicMgr.FlashGiftManager.showNewFlashGift, false)
                -- showUI(PanelNames.UICommonItemGet, nil, nil, 3, rewards, logicMgr.FlashGiftManager.showNewFlashGift);
            else
                logicMgr.FlashGiftManager.showNewFlashGift();
            end
        end
    end);
end

function ActiveManager.initAllActive(data)
    if data == nil then return end
    local time = HelperFunc.GetServerTime();
    for k, v in pairs(data) do
        this.activeServerDataList[tostring(v.activeId)] = v;
        v.isShow = v.state == 1;
        if time >= v.startTime then
            if this.checkActiveOpen(v.activeId) then
                if v.state == 1 then
                    this.initOneActive(v.activeId);
                    this.addPopTipsById(v.activeId);
                else
                    this.removeOneActive(v.activeId);
                end
            else
                if this.limitActiveList == nil then
                    this.limitActiveList = {};
                end
                table.insert(this.limitActiveList, v.activeId);
            end
        else
            this.removeOneActive(v.activeId);
            if this.activeBeginTime[v.activeId] ~= nil then
                utimer.remove(this.activeBeginTime[v.activeId]);
            end
            this.activeBeginTime[v.activeId] = utimer.timeCall(function()
                this.initAllActive({this.getActiveServerDataList(v.activeId)});
                FireEvent(Config.EventType.Fresh_Active);
            end, (v.startTime - time) * 1000, 1);
        end
        --this.addSealCrystalActivityBuff(v.activeId);
    end
    this.reqActivityExtendedData();
end

function ActiveManager.initOneActive(id)
    if id == nil then return end
    local tableData = this.getActiveTableList(id) 
    if tableData == nil then return end
    local serverData = this.getActiveServerDataList(id) 
    if serverData == nil then return end

    local time = HelperFunc.GetServerTime();
    if serverData.drawEndTime < 0 or serverData.drawEndTime > time then
        if this.activeEndTime[serverData.activeId] ~= nil then
            utimer.remove(this.activeEndTime[serverData.activeId]);
        end
        if serverData.drawEndTime > 0 then
            this.activeEndTime[serverData.activeId] = utimer.timeCall(function()
                this.removeOneActive(id);
            end, (serverData.drawEndTime - time) * 1000, 1);
        end
        for k, v in pairs(EnumConst.ActiveShowType) do
            if ZZMathBit.andOp(tableData.f_ShowPos, v) > 0 then
                if this.entranceList[tostring(v)] == nil then
                    this.entranceList[tostring(v)] = {};
                end
                local flag;
                for key, value in pairs(this.entranceList[tostring(v)]) do
                    if value.activeId == serverData.activeId then
                        flag = value;
                    end
                end
                if not flag then
                    flag = {};
                    flag.order = tableData.f_Order;
                    if v == EnumConst.ActiveShowType.LeftSidebar then
                        flag.f_ID = serverData.activeId;
                        flag.activeId = serverData.activeId;
                        flag.id = serverData.activeId;
                        flag.f_FuntionType = 1;
                        flag.f_Icon = tableData.f_Icon;
                        flag.f_OpenUI = tableData.f_InterSurface;
                        flag.f_Desc = tableData.f_IconName;
                        flag.f_HintType = tableData.f_HintType;
                        flag.f_FuncOpen = "";
                    else
                        --if v == EnumConst.ActiveShowType.ActiveCenter or
                        --        v ==  EnumConst.ActiveShowType.PeriodicActivities or
                        --        v ==  EnumConst.ActiveShowType.TimeLimit or
                        --        v ==  EnumConst.ActiveShowType.Forever then
                        flag.activeId = serverData.activeId;
                        flag.openUI = tableData.f_InterSurface;
                        flag.redDots = tableData.f_HintType;
                        flag.titlePic = tableData.f_TitlePic;
                        flag.backgroundPic = tableData.f_BackgroundPic;
                        flag.showTimeType = tableData.f_showTime;
                        flag.titleTips = tableData.f_TitleTips;
                        flag.title = getLanguage(tableData.f_ActivityName);
                        flag.activeType = tableData.f_ActivityType;
                    end
                    table.insert(this.entranceList[tostring(v)], flag);
                end
                flag.startTime = serverData.startTime;
                flag.endTime = serverData.endTime;
                flag.collectTime = serverData.drawEndTime;
                table.sort(this.entranceList[tostring(v)], function(a, b)
                    return a.order < b.order;
                end);
            end
        end
    else
        this.removeOneActive(id);
    end
end

function ActiveManager.removeOneActive(id)
    local tableData = this.getActiveTableList(id);
    local serverData = this.getActiveServerDataList(id);
    if id == nil or tableData == nil or serverData == nil then
        return ;
    end
    local flag;
    for key, value in pairs(this.entranceList) do
        for k, v in pairs(value) do
            if v.activeId == serverData.activeId then
                flag = true;
                table.remove(value, k);
                break ;
            end
        end
    end
    if flag then
        FireEvent(Config.EventType.Fresh_Active);
    end
end

-- 获取活动的额外数据
function ActiveManager.reqActivityExtendedData()
    for k, v in pairs(EnumConst.ActiveShowType) do
        local activeBtnTab = this.getActiveEntranceDataListByType(v);
        for i = 1, #activeBtnTab do
            if tonumber(activeBtnTab[i].activeType) == 28 then
                local acId = activeBtnTab[i].activeId;
                local serverData = this.getActiveServerDataList(acId);
                local serverTime = HelperFunc.GetServerTime();
                if serverTime >= serverData.startTime and serverData.state == 1 and (serverData.drawEndTime < 0 or (serverData.drawEndTime > 0 and serverTime <= serverData.drawEndTime)) then
                    this.ClearTurntableTaskList()
                    --local serverRankInfo = this.GetTurntableRankInfo(acId,1);
                    --local version = -1;
                    --if serverRankInfo then
                    --    version = serverRankInfo.rankVersion;
                    --end
                    --ActivityHandler.sendReqTurntableRankListInfoMessage(acId,1,version);
                    local serverRankInfo = this.GetTurntableRankInfo(acId,2);
                    local version = -1;
                    if serverRankInfo then
                        version = serverRankInfo.rankVersion;
                    end
                    ActivityHandler.sendReqTurntableActivityInfoMessage(acId);
                    ActivityHandler.sendReqTurntableTaskListInfoMessage(acId);
                    ActivityHandler.sendReqTurntableRankListInfoMessage(acId,2,version);
                end
            end
        end
    end
end

function ActiveManager.updateTurntableActivityInfo(id, info)
    this.turntableActivityDataList[tostring(id)] = info;
end
function ActiveManager.updateTurntableActivityAwardPool(id, awardPool)
    local info = this.turntableActivityDataList[tostring(id)];
    if info == nil then
        return;
    end
    info.awardPool = awardPool;
    info.resetCount = tonumber(info.resetCount) + 1;
    this.turntableActivityDataList[tostring(id)] = info;
end
---@return TurntableActivityInfo
function ActiveManager.GetTurntableActivityInfo(id)
    return this.turntableActivityDataList[tostring(id)]
end
function ActiveManager.ClearTurntableTaskList()
    this.turntableTaskDataList = {}
end
function ActiveManager.updateTurntableTaskListInfo(id, info)
    local task = this.turntableTaskDataList[tostring(id)] or {}
    for k, v in pairs(info) do
        local taskInfo = {};
        taskInfo.process = v.process;
        taskInfo.recvStatus = v.recvStatus;
        task[tostring(v.taskId)] = taskInfo;
    end
    this.turntableTaskDataList[tostring(id)] = task;
end
function ActiveManager.refreshTurntableTaskListInfo(id, taskId)
    local task = this.turntableTaskDataList[tostring(id)];
    if task ~= nil and task[tostring(taskId)] ~= nil then
        local taskInfo = {};
        taskInfo.process = task[tostring(taskId)].process;
        taskInfo.recvStatus = 1;
        task[tostring(taskId)] = taskInfo;
        this.turntableTaskDataList[tostring(id)] = task;
    end
end
function ActiveManager.GetTurntableRankInfo(activityId,rankType)
    local data = this.turntableRankDataList[tostring(activityId)]
    if not data then return nil end
    return data[tostring(rankType)]
end
function ActiveManager.GetTurntableTaskData(activityId,taskId)
    local data = this.turntableTaskDataList[tostring(activityId)]
    if not data then return nil end
    return data[tostring(taskId)]
end
function ActiveManager.updateTurntableRankData(msg)
    local actId = msg.activityId;
    local data = this.turntableRankDataList[tostring(actId)];
    if data == nil then
        data = {};
        local info = {};
        info.rankList = msg.rankList;
        info.selfRank = tonumber(msg.selfRank);
        info.selfOrderVal = tonumber(msg.selfOrderVal);
        info.rankVersion = msg.rankVersion;
        data[tostring(msg.rankType)] = info;
    elseif data[tostring(msg.rankType)] == nil or tonumber(data[tostring(msg.rankType)].rankVersion) ~= tonumber(msg.rankVersion) then
        local info = {};
        info.rankList = msg.rankList;
        info.selfRank = tonumber(msg.selfRank);
        info.selfOrderVal = tonumber(msg.selfOrderVal);
        info.rankVersion = msg.rankVersion;
        data[tostring(msg.rankType)] = info;
    end
    this.turntableRankDataList[tostring(actId)] = data;
end

function ActiveManager.updateActiveData(id)
    local activeList = {};
    --local tableData = activeEntranceTableData;
    if id == nil then
        return ;
    end
    --for k, v in pairsByKeys(activeEntranceTableData) do
        local data = {};
        local tableData = this.getActiveTableList(id);
        if tableData ~= nil then
            local flag = true;
            local startTime = 0;
            startTime = this.getDataUpateTime(logicMgr.HeroManager.GetRoleInfo().createTime);
            data.activeId = tableData.f_ActivityId;
            data.startTime = startTime;
            data.endTime = startTime + 7 * 24 * 60 * 60;
            data.drawEndTime = startTime + 9 * 24 * 60 * 60;
            data.state = 1;
            data.updateParam = 0;
            if tableData.f_ActivityId == 10001 then
                data.drawEndTime = -1;
                if (#ActiveManager.sevenDayInfotab <= 0) then
                    flag = false;
                end
            end
            if flag then
                table.insert(activeList, data);
            end
        end
    --end
    this.initAllActive(activeList);
    FireEvent(Config.EventType.Fresh_Active);
end

function ActiveManager.getDataUpateTime(time, offset)
    if time == nil or time <= 0 then
        return 0;
    end
    offset = offset or 3
    local temp = os.date("*t", math.floor(time));
    --local toTime = os.time({year = temp.year, month = temp.month, day = temp.day, hour = 0, min = 0, sec = 0});
    local toTime = time - (temp.hour * 60 + temp.min) * 60 - temp.sec + offset;
    local updateTime = G.dataTable["t_global"][tostring(35)].f_int_value;
    toTime = toTime + updateTime;
    if temp.hour * 60 * 60  < updateTime then
        toTime = toTime - 24 * 60 * 60;
    end
    return toTime;
end

function ActiveManager.getDataUpateTimeGMT8(time)
    if time == nil or time <= 0 then
        return 0;
    end
    local temp = os.date("!*t", math.floor(time + 8*3600));
    --local toTime = os.time({year = temp.year, month = temp.month, day = temp.day, hour = 0, min = 0, sec = 0});
    local toTime = time - (temp.hour * 60 + temp.min) * 60 - temp.sec + 3;
    local updateTime = G.dataTable["t_global"][tostring(35)].f_int_value;
    toTime = toTime + updateTime;
    if temp.hour * 60 * 60  < updateTime then
        toTime = toTime - 24 * 60 * 60;
    end
    return toTime;
end

function ActiveManager.timingUpdate()
    if this.updateTime ~= nil then
        return ;
    end
    local time = HelperFunc.GetServerTime();
    local openTime = this.getDataUpateTime( time + 24 * 60 * 60);
    this.updateTime = utimer.timeCall(function()
        --七天登陆
        ActivityHandler.sendReqSevenDayMessage();
        --当天在线时长
        logicMgr.HeroManager.setOnlineTime(5);
        --任务
        taskInfoHandler.sendReqTaskMessage();
        -- 爬塔红点
        RedDotsClimbTowerHandler.update();
        --好感度数量重新计算
        logicMgr.HeroManager.updateInteractionNum()

        -- 特殊登录领奖励
        --this.TempSpecialLoginAwardSeverData();
        --前端临时维护的数据
        --this.TempActiveServerData();
        --重新获取集市活动(卫峰整的恶心集市类型，后面要是改和时间有关需求干死他)
        local severData = logicMgr.CostManager.getActiveServerDataList(10210);
        if severData ~= nil then
            costHandler.reqGetOneMarketInfo(10210);
        end
        -- 刷新活动
        ActivityHandler.sendReqActivityInfoListMessage()
        -- 职业爬塔刷新
        FireEvent(Config.EventType.Fresh_AdvancedTower);
        -- 高阶竞技场新赛季
        FireEvent(Config.EventType.Fresh_CrossTeamArenaRed);
        logicMgr.HeroManager.setQuickTimes(0);
        -- 解锁功能，发起协议
        logicMgr.UnlockFuncManager.updateUnlockFunc();
        this.updateTime = nil;
        ActiveManager.timingUpdate();
        -- 抽奖次数
        FireEvent(Config.EventType.Fresh_Draw)
        -- 许愿池抽奖次数
        FireEvent(Config.EventType.WishPondSourceChange)
        printError("============跨天了===========")
    end, (openTime - time + 5) * 1000, 1);
end

function ActiveManager.HourHeartbeat()
    local time = HelperFunc.GetServerTime();
    local temp = os.date("*t", math.floor(time));
    local toTime = os.time({year = temp.year, month = temp.month, day = temp.day, hour = temp.hour, min = 0, sec = 0});
    toTime = toTime + 60 * 60;
    if  this.updateHourTime ~= nil then
        utimer.remove(this.updateHourTime)
        this.updateHourTime = nil;
    end
    this.updateHourTime = utimer.timeCall(function()
        --this.TempDessertServerData();
        logicMgr.NoticeManager.TempSevenRankSigninServerData();
        logicMgr.ArenaManager.TempCrossTeamAwardCount();
        ActiveManager.HourHeartbeat();
    end, (toTime - time + 5) * 1000, 1);
end

function ActiveManager.isHaveSevenDay()
    return #ActiveManager.sevenDayInfotab > 0;
end

function ActiveManager.checkActiveOpen(id)
    local tableData = this.getActiveTableList(id);
    if tableData == nil then
        return false;
    end
    return logicMgr.TaskManager.conditionAndJudge(decodeJsonStrToTabel(tableData.f_Condition))
end

function ActiveManager.updateActiveLimit()
    local data = {};
    if this.limitActiveList == nil then
        return ;
    end
    for k, v in pairs(this.limitActiveList) do
        local tableData = this.getActiveTableList(v);
        if tableData ~= nil then
            if logicMgr.TaskManager.conditionAndJudge(decodeJsonStrToTabel(tableData.f_Condition)) then
                this.initAllActive({this.getActiveServerDataList(v)});
            else
                table.insert(data, v);
            end
        end
    end
    this.limitActiveList = data;
end

-- 更新打开类页签红点状态
function ActiveManager.updateActiveOpenStatus(id, type)
    type = type or 2;
    if type == 1 then
        if GetPlayerPrefsAfter5AMFlag("redDotOne"..logicMgr.HeroManager.GetRoleInfo().playerId.."_active_id:"..id) then
            SetPlayerPrefsAfter5AMFlag("redDotOne"..logicMgr.HeroManager.GetRoleInfo().playerId.."_active_id:"..id)
            FireEvent(Config.EventType.Fresh_Active);
        end
    elseif type == 2 then
        local serverData = this.getActiveServerDataList(id);
        if serverData and GetPlayerPrefs("redDotOne"..serverData.startTime.."_active_id:"..id) ~= "true" then
            SetPlayerPrefs("redDotOne"..serverData.startTime.."_active_id:"..id, "true")
            FireEvent(Config.EventType.Fresh_Active);
        end
    end
end

function ActiveManager.getActiveOpenStatus(id, type)
    type = type or 2;
    if type == 1 then
        if GetPlayerPrefsAfter5AMFlag("redDotOne"..logicMgr.HeroManager.GetRoleInfo().playerId.."_active_id:"..id) then
            return true;
        else
            return nil;
        end
    elseif type == 2 then
        local serverData = this.getActiveServerDataList(id);
        if serverData and GetPlayerPrefs("redDotOne"..serverData.startTime.."_active_id:"..id) ~= "true" then
            return true;
        else
            return nil;
        end
    end
end

---------------------------------------处理后端数据------------开始--------------
function ActiveManager.getActiveData(activeId)
    -- 返回值中第二个一定得是后端数据,isShow,RedDots等都是统一在第二个返回参数中取
    if activeId == nil then
        return ;
    end
    local activeTable = this.getActiveTableList(activeId);
    if activeTable == nil then
        return ;
    end
    local type = tonumber(activeTable.f_ActivityType);
    if type == 5 then
        return this.disposeLoginAwardSeverData(activeId);
    elseif type == 6 then
        return this.disposeDoubleAwardSeverData(activeId);
    elseif type == 1 then
        return this.disposeSevendaySeverData(activeId);
    elseif type == 2 then
        return this.disposeSevenChallengeSeverData(activeId);
    elseif type == 7 then
        return this.disposeSpecialDrawSeverData(activeId);
    elseif type == 8 then
        return this.disposeHeroCollectData(activeId);
    elseif type == 9 then
        return this.disposeSpecialLoginAwardSeverData(activeId);
    elseif type == 10 then
        return this.disposeCenterActivitySeverData(activeId);
    elseif type == 11 then
        return this.disposeActivityListTaskSeverData(activeId);
    elseif type == 12 then
        return this.disposeActivityListExchangeSeverData(activeId);
    elseif type == 13 then
        return this.disposeUIActivityListShopSeverData(activeId);
    elseif type == 14 then
        return this.disposeTotalRechargeSeverData(activeId);
    elseif type == 15 then
        return this.disposeDessertSeverData(activeId);
    elseif type == 16 then
        return this.disposeSealCrystalSeverData(activeId);
    elseif type == 17 then
        return this.disposeActivitySignInSeverData(activeId);
    elseif type==18 then
        return this.disposeDailyChargeServerData(activeId);
    elseif type==19 then
        return this.disposeAccumulateFirstPayData(activeId);
    elseif type==20 then
        return this.disposeActivityDrawData(activeId);
    elseif type==22 then
        return this.disposeActivitySpTaskSeverData(activeId);
    elseif type==23 then
        return this.disposeLayerChargeData(activeId);
    elseif type==24 then
        return this.disposeWelfareSeverData(activeId)
    elseif type==25 then
        return this.disposeQuestionSeverData(activeId)
    elseif type==26 then
        return this.disposeOnlineSeverData(activeId)
    elseif type == 27 then
        return this.disposeNewPlayerData(activeId)
    elseif type==29 then
        return this.disposeSoloChaosTestSeverData(activeId)
    elseif type == 28 then
        return this.disposeLuckyGuySeverData(activeId)
    elseif type == 32 then
        return this.disposeChristmasTreeData(activeId)
    elseif type == 30 then
        return this.disposeCelebrationData(activeId)
    elseif type == 33 then
        return this.disposeActivityFreeData(activeId)
    elseif type == 34 then
        return this.disposeActivityBattlePass(activeId)
    elseif type == 35 then
        return this.disposeActivityCardServerData(activeId)
    elseif type == 36 then
        return this.disposeDivineInspirationData(activeId)
    elseif type == 37 then
        return this.disposeDivineInspirationExchageData(activeId)
    elseif type == 38 then
        return this.disposeDivineInspirationGiftData(activeId)
    elseif type == 39 then
        return this.disposeBlindBoxData(activeId)
    elseif type == 43 then
        return this.disposeActivityExplorSeverData(activeId)
    else
        return;
    end
end

function ActiveManager.getActiveBeginDay(time)
    if time == nil then
        return 0;
    end
    local openTime = this.getDataUpateTime(time);
    time = math.floor(HelperFunc.GetServerTime()) - openTime;
    if time > 0 then
        return math.floor((time + 24*60*60-1) / (24*60*60));
    end
    return 0;
end

function ActiveManager.getActiveInitialDataById(id)
    local tableData = this.getActiveTableList(id);
    if tableData == nil then
        return;
    end
    local modelTableData = {};
    if tableData.f_ModelName ~= "" then
        modelTableData = G.dataTable[tableData.f_ModelName];
    end
    local itemTableData = modelTableData[tostring(id)];
    local serverData = this.getActiveServerDataList(id);
    return tableData, itemTableData, serverData, modelTableData;
end

function ActiveManager.disposeLayerChargeData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end
    local data = G.dataTable[tostring(itemTableData.f_ItemTableName)];
    --local curPeriodAwards = nil  --当前期活动当前档次的所有奖励
    local itemData = {};
    local extraAwardData = {}
    for _,v in pairs(data) do
        if v.f_DailyRechargeId == serverData.param.payCfgId then
            local curPeriodAwards = decodeJsonStrToTabel(v.f_Award) or {}
            local dayList = decodeJsonStrToTabel(v.f_Day) or {}
            local extraAwardList = decodeJsonStrToTabel(v.f_AwardDay) or {}
            for m,n in pairs(curPeriodAwards) do
                local award = {}
                award.f_ItemId=v.f_DailyRechargeId
                award.f_Price=v.f_DailyCumulativeRecharge
                award.f_Award=n
                table.insert(itemData, award);
            end
            for m,n in pairs(dayList) do
                table.insert(extraAwardData,{awardList = extraAwardList[m], dayIndex = n})
                --extraAwardData[n] =  {awardList = extraAwardList[m]}
            end
            break
        end
    end
    serverData.itemData = itemData
    serverData.extraAwardData = extraAwardData
    serverData.endTime = serverData.param.endTime / 1000;
    --奖励领取列表
    local rewardedSet={};
    local achieveDays = 0   --达标天数
    for k,v in pairs(serverData.param.recentlyDailyPay)do
        local price=itemData[1].f_Price
        local getState     --0未满足 1可领取 2 已领取
        if v.rewarded then
            getState =2
            achieveDays = achieveDays + 1
        elseif v.pay>=price then
            getState =1
            achieveDays = achieveDays + 1
        else
            getState =0
        end
        --local dayIndex = v[1]
        rewardedSet[tonumber(k)]={state=getState,payNum=v.pay,extraStatus = v.giftStatus}
    end
    serverData.rewardedSet = rewardedSet;
    serverData.achieveDays = achieveDays;
    for k,v in pairs(serverData.param.totalDayAward)do
        for m,n in pairs(serverData.extraAwardData) do
            if n.dayIndex == tonumber(k) then
                n.status = v
            end
        end
    end
    local now = HelperFunc.GetServerTime()
    local activeStartDays = GetTimeStampDayDis(math.floor(tonumber(tostring(serverData.startTime))),now)   --活动开启距离现在多少天
    local curPeriodDays = (activeStartDays % 7) + 1 --现在是当前期活动的第几天  --TODO 活动周期走配表
    local borderIndex = #rewardedSet   --当前补位天数是第几天
    for i = 1, curPeriodDays do
        if rewardedSet[i] == nil or rewardedSet[i].payNum < itemData[1].f_Price then
            borderIndex = i
        end
    end
    serverData.curPeriodDays = curPeriodDays
    serverData.borderIndex = borderIndex
    serverData.redDots=false
    for _,v in pairs(rewardedSet)do
        if v.state==1 or v.extraStatus == 1 then
            serverData.redDots=true
            break
        end
    end
    for _,v in pairs(serverData.param.totalDayAward)do
        if v == 1 then
            serverData.redDots=true
            break
        end
    end
    return tableData,serverData
end

function ActiveManager.disposeNewPlayerData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id)
    if serverData == nil or tableData == nil or itemTableData == nil then
        return
    end
    local data = G.dataTable[tostring(itemTableData.f_ItemTableName)]
    local boxData, extraBoxData, taskData = logicMgr.NewPlayerActiveManager.GetBoxAndTaskData()
    serverData.redDots = false
    if boxData and extraBoxData and taskData then
        for k,v in pairs(boxData) do
            if v.state == 1 then
                serverData.redDots = true
                break
            end
        end
        for k,v in pairs(extraBoxData) do
            if v.state == 1 then
                serverData.redDots = true
                break
            end
        end
        for k,v in pairs(taskData) do
            if v.state == 2 then
                serverData.redDots = true
                break
            end
        end
    end
    return tableData,serverData,data
end

function ActiveManager.disposeDailyChargeServerData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end

    local data = G.dataTable[tostring(itemTableData.f_ItemTableName)];
    local order=serverData.param.periods
    --筛选当前期次数据
    local itemData = {};
    for k,v in pairs(data) do
        if tonumber(v.f_ActivityId) == tonumber(id) and v.f_Num==order then
            v.f_ItemId=v.f_DailyRechargeId
            v.f_Price=v.f_DailyCumulativeRecharge
            table.insert(itemData, v);
        end
    end
    table.sort(itemData, function(a, b)
        return a.f_DailyRechargeId < b.f_DailyRechargeId;
    end);

    serverData.itemData = itemData;
    serverData.endTime=serverData.param.endTime / 1000;
    --奖励领取列表
    local rewardedSet={};
    for i,v in pairs(serverData.param.payRecordMap)do
        local price=itemData[1].f_Price
        local getState     --0未满足 1可领取 2 已领取
        if v.rewarded then
            getState =2
        elseif v.todayPay>=price then
            getState =1
        else
            getState =0
        end
        rewardedSet[v.rewardId]={state=getState,payNum=v.todayPay}
    end
    serverData.rewardedSet = rewardedSet;
    local now=HelperFunc.GetServerTime()
    serverData.today=GetTimeStampDayDis(math.floor(tonumber(tostring(serverData.param.startTime))/1000),now)+1
    serverData.todayPay=0
    serverData.todayState=0
    serverData.todayID=-1
    local todayData=nil
    for i,v in pairs(serverData.param.payRecordMap)do
        if v.distDay==serverData.today then
            todayData=v
            break
        end
    end
    if todayData~=nil then
        serverData.todayPay=todayData.todayPay
        serverData.todayState=todayData.state
        --serverData.todayID=todayData.rewardId
    end
	if serverData.param.rewardId ~= nil then
        serverData.todayID=serverData.param.rewardId
    end
    serverData.redDots=false
    for i,v in pairs(rewardedSet)do
        if v.state==1 then
            serverData.redDots=true
            break
        end
    end
    return itemTableData, serverData;
end
function ActiveManager.disposeAccumulateFirstPayData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end
    local itemData = itemTableData
    local state=-1 --0:未首充 1:今日未领取2：次日领取 3：已经领取完
    local serverItemData={}

    if serverData.param ~= nil then
        serverItemData.totalPay=ConvertCSharpLongNumber(serverData.param.totalPay)
        serverItemData.unlockTime=ConvertCSharpLongNumber(serverData.param.unlockTime)
        serverItemData.rewardedSet=serverData.param.rewardedSet
        serverItemData.dayNum=0
        if serverItemData.unlockTime==0 then
            state=0
        else
            local day=GetTimeStampDayDis((serverItemData.unlockTime/1000),HelperFunc.GetServerTime())+1
            serverItemData.dayNum=day
            if #serverItemData.rewardedSet==7 then
                state =3
            else
                if day>#serverItemData.rewardedSet then
                    state=1
                else
                    state=2
                end
            end
        end
    end
    if not logicMgr.TaskManager.conditionAndJudge(tableData.f_Condition) then
         state=-1
    end
    return state,itemData,serverItemData
end

function ActiveManager.disposeActivityDrawData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return
    end
    serverData.redDots = this.getActiveOpenStatus(id, 2);
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    return itemTableData, serverData;
end

function ActiveManager.disposeSevendaySeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if RedDotsSevenDayProcessHandler.getFlag() == Config.RedDotsFlagState.Needful then
        serverData.redDots = true;
    else
        serverData.redDots = nil;
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    return itemTableData, serverData;
end

local assembleTask;
local assembleTaskBox;
function ActiveManager.disposeHeroCollectData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    serverData.redDots = nil;
    if assembleTask == nil then
        assembleTask = G.dataTable["t_assembletask"];
        assembleTaskBox = G.dataTable["t_assembletaskbox"];
    end
    if serverData.param.assembleTaskMap ~= nil then
        for k, v in pairs(serverData.param.assembleTaskMap) do
            local taskConfig = assembleTask[tostring(k)];
            if taskConfig ~= nil then
                if tonumber(taskConfig.f_Show) == 1 then
                    if not v.rewarded and tonumber(v.process) >= tonumber(taskConfig.f_Progress) then
                        serverData.redDots = true;
                        break;
                    end
                end
            end
        end
    end

    local maxExp = 0;
    for k, v in pairs(assembleTaskBox) do
        local needExpCount = tonumber(v.f_NeedExpCount);
        if needExpCount > maxExp then
            maxExp = needExpCount;
        end
    end
    local score = 0;
    if serverData.param.score ~= nil then
        score = tonumber(serverData.param.score);
    end
    if serverData.redDots == nil then
        local boxRewardedSet = serverData.param.boxRewardedSet;
        local hasGet = false;
        for k, v in pairs(assembleTaskBox) do
            local needExpCount = tonumber(v.f_NeedExpCount);
            if score >= needExpCount then
                hasGet = false;
                if boxRewardedSet ~= nil then
                    for boxK, boxV in pairs(boxRewardedSet) do
                        if tonumber(k) == tonumber(boxV) then
                            hasGet = true;
                        end
                    end
                    if not hasGet then
                        serverData.redDots = true;
                        break ;
                    end
                else
                    serverData.redDots = true;
                    break ;
                end
            end
        end
    end

    if score >= maxExp then
        serverData.dailyRewardState = -1;
    else
        if this.HasHeroCollectDailyReward(serverData) then
            serverData.dailyRewardState = 0;
            serverData.redDots = true;
        else
            serverData.dailyRewardState = -1;
        end
    end

    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 then
        serverData.isShow = false;
    else
        if serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
            serverData.isShow = false;
        else
            serverData.isShow = true;
        end
    end
    
    return itemTableData, serverData;
end
--money:累充钱数，endTime:结束时间,maxStage:最大等级数,stage:当前等级,index:当前等级对应的索引，today：天数，lastGetLevel:最后领取等级,lastGetDay最后领取天数
--todayStartLevel：今天早上五点的等级,lastGetIndex,todayStartIndex:对应showdata的index,offSetStates:差额奖励领取状态
function ActiveManager.disposeWelfareSeverData(id)
    local _, itemTableData, serverDatas = this.getActiveInitialDataById(id);
    if serverDatas == nil then
        return;
    end
    local netData={}
    local serverData=serverDatas.param
    serverData.totalPay=serverData.totalPay or 0
    serverData.lastGetTime=serverData.lastGetTime or 0

    netData.money=serverData.totalPay
    netData.endTime=serverDatas.endTime

    local data={}
    local tableData = G.dataTable["t_activitywelfarerward"]
    tableData =SortTableData(tableData,"f_Id")
    netData.maxStage=#tableData
    for i,v in ipairs(tableData)do
        if netData.money<v.f_Price then
           break
        end
        netData.stage=toNumber(v.f_Id)
        TAManager.UserSet("vip_welfare", v.f_Id)
    end
    local startTime=ConvertCSharpLongNumber(serverDatas.startTime)
    netData.today=GetTimeStampDayDis(startTime,HelperFunc.GetServerTime())+1
    netData.lastGetLevel =serverData.lastGetLevel or 0
    netData.lastGetDay=0
    if serverData.lastGetTime~=0 then
        netData.lastGetDay=GetTimeStampDayDis(startTime,ConvertCSharpLongNumber(serverData.lastGetTime)/1000)+1
    end

    --netData.offSetStates={} --存储已领取的差值奖励 id:state
    --netData.offSetDays={}   --存储前一等级持续天数 id:days
    netData.offsetData={}
    local max=0
    for i,v in pairs(serverData.levelDatas or {})do
        netData.offsetData[tonumber(i)]=v
        max=Mathf.Max(max,tonumber(i))
    end
    for i=max-1,1,-1 do
        if netData.offsetData[i]==nil then
            netData.offsetData[i]=clone(netData.offsetData[i+1])
        end
    end
    netData.todayState=0
    local lastGetTime=ConvertCSharpLongNumber(serverData.lastGetTime)/1000
    local day=GetTimeStampDayDis(lastGetTime,HelperFunc.GetServerTime())
    if day<=0 and netData.lastGetLevel==netData.stage then
        netData.todayState=1
    end
    netData.dayNum=netData.today-netData.lastGetDay
    local showDatas={}
    netData.index=1
    netData.lastGetIndex=0
    for i,v in ipairs(tableData)do
        if v.f_UnlockLv >netData.stage then
            break
        end
        if v.f_Id==netData.stage then
            netData.index=i
        end
        if v.f_Id==netData.lastGetLevel then
            netData.lastGetIndex=i
        end
        table.insert(showDatas,v)
    end

    netData.redDots=true
    if netData.todayState==1 then
        netData.redDots=false
    end
    data.showDatas=showDatas
    local modelData=G.dataTable["t_activitywelfaremodel"][tostring(id)]
    return data,netData,modelData
end
---调查问卷
function ActiveManager.disposeQuestionSeverData(id)
    local tableData, itemTableData, serverData, modelTableData = this.getActiveInitialDataById(id);
    if tableData == nil or serverData == nil then
        return ;
    end
    local itemList = {};
    local nowTime = HelperFunc.GetServerTime();
    serverData.param.rewardList = serverData.param.rewardList or {};
    serverData.redDots = this.getActiveOpenStatus(id);
    for k, v in pairs(modelTableData) do
        if v.f_ActivityId == id and v.f_IsHide == 0 then
            if v.f_OpenTime <= nowTime and (v.f_EndTime == -1 or v.f_EndTime > nowTime)  then
                v.received = logicMgr.CostManager.isExistInListByValue(serverData.param.rewardList, v.f_Id)
                table.insert(itemList, v);
                if not v.received and logicMgr.CostManager.isOpenItem(v) then
                    serverData.redDots = true;
                end
            end
        end
    end
    table.sort(itemList, function (a, b)
        return a.f_Sort < b.f_Sort;
    end);
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    serverData.itemList = itemList;
    return tableData, serverData;
end
---在线时间
function ActiveManager.disposeOnlineSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if tableData == nil or serverData == nil then
        return ;
    end
    local itemList = {};
    local config = G.dataTable["t_onlineaward"];
    serverData.param.rewardList = serverData.param.rewardList or {};
    serverData.redDots = this.getActiveOpenStatus(id);
    local nowOnlineTime = logicMgr.HeroManager.getOnlineTime();
    local nowDay = serverData.param.day or this.getActiveBeginDay(serverData.startTime);
    serverData.nowDay = nowDay;
    local nextTime = -1;
    for k, v in pairs(config) do
        if v.f_ActivityId == id and v.f_Day == nowDay then
            v.received = logicMgr.CostManager.isExistInListByValue(serverData.param.todayRecvs, v.f_Id)
            if v.received == false then
                if v.f_Time <= nowOnlineTime then
                    serverData.redDots = true;
                elseif nextTime == -1 or v.f_Time < nextTime then
                    nextTime = v.f_Time;
                end
            end
            table.insert(itemList, v);
        end
    end
    table.sort(itemList, function (a, b)
        return a.f_Time < b.f_Time;
    end);
    serverData.itemList = itemList;
    local boxList = {};
    local boxDay = decodeJsonStrToTabel(itemTableData.f_Day);
    local boxReward = decodeJsonStrToTabel(itemTableData.f_Reward);
    serverData.param.canRecvDays = serverData.param.canRecvDays or {};
    --serverData.param.reachedDay = #serverData.param.canRecvDays
    for k, v in pairs(boxDay) do
        local data = {};
        data.day = v;
        data.rewards = boxReward[k] or {};
        data.received = logicMgr.CostManager.isExistInListByValue(serverData.param.recvDays, v);
        if data.received == false and v <= serverData.param.reachedDay then
            serverData.redDots = true;
        end
        table.insert(boxList, data);
    end
    table.sort(boxList, function (a, b)
        return a.day < b.day;
    end);
    serverData.boxList = boxList;
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    if serverData.isShow and not serverData.redDots and nextTime > 0 then
        logicMgr.HeroManager.setOnlineTimeNode(nextTime, function ()
            FireEvent(Config.EventType.Fresh_Active);
        end);
    end
    return tableData, serverData, itemTableData;
end

function ActiveManager.HasHeroCollectDailyReward(serverData)
    if serverData == nil or serverData.param == nil or serverData.param.lastRewardedTime == nil then
        return true;
    else
        local lastRewardedTime = tonumber(serverData.param.lastRewardedTime);
        if lastRewardedTime == 0 then
            return true;
        else
            local time = HelperFunc.GetServerTime();
            lastRewardedTime = lastRewardedTime / 1000;
            local temp = os.date("*t", math.floor(lastRewardedTime));
            local toTime;
            local updateTime = G.dataTable["t_global"][tostring(35)].f_int_value;
            if temp.hour * 60 * 60  >= updateTime then
                temp = os.date("*t", math.floor(lastRewardedTime + 24 * 60 * 60));
            end
            toTime = os.time({year = temp.year, month = temp.month, day = temp.day, hour = 5, min = 0, sec = 0});
            if time >= toTime then
                return true;
            end
        end
    end
    return false;
end

---七天挑战
function ActiveManager.disposeSevenChallengeSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if RedDotsSevenChallengeHandler.getFlag() == Config.RedDotsFlagState.Needful then
        serverData.redDots = true;
    else
        serverData.redDots = nil;
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    return itemTableData, serverData;
end

function ActiveManager.disposeLoginAwardSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return ;
    end
    serverData.receive = {};
    local redDots;
    local day = this.getActiveBeginDay(serverData.startTime);
    for i = 1, itemTableData.f_DayTime do
        if i > day then
            serverData.receive[i] = 0;
        elseif serverData.param.rewardStatusMap == nil or serverData.param.rewardStatusMap[tostring(i)] ~= 1 then
            serverData.receive[i] = 1;
            redDots = true;
        else
            serverData.receive[i] = -1;
        end
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    serverData.redDots = redDots;
    itemTableData.f_Rewards = decodeJsonStrToTabel(itemTableData.f_Rewards);
    itemTableData.f_TitleAward = decodeJsonStrToTabel(itemTableData.f_TitleAward);
    return itemTableData, serverData;
end

function ActiveManager.disposeSpecialLoginAwardSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return ;
    end
    serverData.receive = {};
    local redDots;
    for i = 1, itemTableData.f_DayTime do
        if serverData.param.data == nil or i > #serverData.param.data then
            serverData.receive[i] = 0;
        else
            if tonumber(serverData.param.data[i]) == 0 then
                serverData.receive[i] = 1;
                redDots = true;
            else
                serverData.receive[i] = -1;
            end
        end
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    serverData.redDots = redDots;
    itemTableData.f_Rewards = decodeJsonStrToTabel(itemTableData.f_Rewards);
    itemTableData.f_TitleAward = decodeJsonStrToTabel(itemTableData.f_TitleAward);
    return itemTableData, serverData;
end

function ActiveManager.TempSpecialLoginAwardSeverData()
    local activeBtnTab = this.getActiveEntranceDataListByType(EnumConst.ActiveShowType.ActiveCenter);
    for i = 1, #activeBtnTab do
        if tonumber(activeBtnTab[i].activeType) == 9 then
            local serverData = this.getActiveServerDataList(activeBtnTab[i].activeId);
            if serverData ~= nil then
                if serverData.param.data == nil then
                    serverData.param.data = {};
                end
                table.insert(serverData.param.data, 0);
                this.activeServerDataList[tostring(activeBtnTab[i].activeId)] = serverData;
            end
        end
    end
end

-- 防止同一时间通信量，需要每日5点重置活动信息的前端临时维护
function ActiveManager.TempActiveServerData()
    for k, v in pairs(EnumConst.ActiveShowType) do
        if v == EnumConst.ActiveShowType.ActiveCenter or v == EnumConst.ActiveShowType.PeriodicActivities then
            local activeBtnTab = this.getActiveEntranceDataListByType(v);
            local tableData, itemTableData, serverData;
            for i = 1, #activeBtnTab do
                local type = tonumber(activeBtnTab[i].activeType);
                local activeId = activeBtnTab[i].activeId;
                if type == 11 then
                    tableData, itemTableData, serverData = this.getActiveInitialDataById(activeId);
                    local childModelName = decodeJsonStrToTabel(itemTableData.f_ModelName);
                    local config = G.dataTable[tostring(childModelName[2])];
                    local serverTaskData = serverData.param.taskMap;
                    if serverTaskData ~= nil then
                        for configK, configV in pairs(config) do
                            if configV.f_ActivityId == activeId and 7 == tonumber(configV.f_FunctionType) then
                                --重置数据
                                local taskId = tostring(configV.f_ActTaskId);
                                local taskData = serverTaskData[taskId];
                                if taskData ~= nil then
                                    taskData.rewarded = false;
                                    taskData.process = 0;
                                    serverTaskData[taskId] = taskData;
                                end
                            end
                        end
                    end
                    serverData.param.taskMap = serverTaskData;
                    this.activeServerDataList[tostring(activeId)] = serverData;
                elseif type == 13 then
                    tableData, itemTableData, serverData = this.getActiveInitialDataById(activeId);
                    local data = G.dataTable[itemTableData.f_ItemTableName];
                    local serverBuyCountData = serverData.param.buyCountMap;
                    if serverBuyCountData ~= nil then
                        for dataK, dataV in pairs(data) do
                            if dataV.f_ActivityId == activeId and tonumber(dataV.f_RefreshType) == 2 then
                                --重置数据
                                local itemId = tostring(dataV.f_ItemId);
                                local buyCountData = serverBuyCountData[itemId];
                                if buyCountData ~= nil then
                                    serverBuyCountData[itemId] = 0;
                                end
                            end
                        end
                    end
                    serverData.param.buyCountMap = serverBuyCountData;
                    this.activeServerDataList[tostring(activeId)] = serverData;
                elseif type == 15 then
                    tableData, itemTableData, serverData = this.getActiveInitialDataById(activeId);
                    --[[
                    if serverData.param.data ~= nil then
                        serverData.param.data = nil;
                    end
                    --]]
                    if serverData.param.rewarded ~= nil then
                        serverData.param.rewarded = nil;
                    end
                    this.activeServerDataList[tostring(activeId)] = serverData;
                elseif type == 18 then
                    tableData, itemTableData, serverData = this.getActiveInitialDataById(activeId);
                    local data = G.dataTable[tostring(itemTableData.f_ItemTableName)];
                    local order=serverData.param.periods
                    local nextOrder = order + 1;
                    local hasNext = false;
                    local updateServerData = false;
                    local itemData = {};
                    for k, v in pairs(data) do
                        if tonumber(v.f_ActivityId) == tonumber(activeId) then
                            if v.f_Num == order then
                                table.insert(itemData, v);
                            elseif nextOrder == v.f_Num and not hasNext then
                                hasNext = true;
                            end
                        end
                    end
                    local serverTime = HelperFunc.GetServerTime()
                    local endTime = serverData.param.endTime / 1000;
                    if serverTime >= endTime then
                        --时间到了活动显示下一期
                        updateServerData = true;
                    else
                        --奖励全部领取活动显示下一期
                        local payNum = 0;
                        for i,v in pairs(serverData.param.payRecordMap)do
                            payNum = payNum + 1;
                        end
                        if payNum >= #itemData then
                            updateServerData = true;
                            local temp = os.date("*t", math.floor(serverTime));
                            endTime = os.time({year = temp.year, month = temp.month, day = temp.day, hour = 5, min = 0, sec = 0});
                        end
                    end
                    if updateServerData then
                        serverData.param.payRecordMap = {};
                        if hasNext then
                            serverData.param.periods = serverData.param.periods + 1;
                        end
                        serverData.param.startTime = endTime * 1000;
                        serverData.param.endTime = (endTime + 18 * 24 * 3600) * 1000;

                        this.activeServerDataList[tostring(activeId)] = serverData;
                    end
                end
            end
        end
    end
end

function ActiveManager.disposeDoubleAwardSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    serverData.redDots = this.getActiveOpenStatus(id);
    if not logicMgr.FuncOpenManager.isOpen(itemTableData.f_Switchover, false) then
        serverData.redDots = nil;
    end
    return itemTableData, serverData;
end
SpecialDrawState =
{
    locked=0,
    haveBought=1,
    startDraw=2,
    continueDraw=3,
    waitToBuy=4,
    buy=5,
    canNotBuy=6,
}
---先知召唤
function ActiveManager.disposeSpecialDrawSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return ;
    end
    serverData.param.selectDrawTimes = serverData.param.selectDrawTimes or 0;
    serverData.param.selectDrawBuyTimes = serverData.param.selectDrawBuyTimes or 0;
    serverData.param.selectDrawBox = serverData.param.selectDrawBox or {};
    serverData.param.selectDrawSaved = serverData.param.selectDrawSaved or {};
    serverData.activeState = nil;
    serverData.redDots = nil;
    local cost = decodeJsonStrToTabel(itemTableData.f_Cost);
    cost = cost[1];
    local haveNum = logicMgr.ItemManager.getBagNumByTableID(cost[1]);
    serverData.redDots = false
    local canBuy=haveNum>=cost[2]
    local isLocked=false
    if itemTableData.f_OpenType == 1 then
        if serverData.startTime + itemTableData.f_OpenParm > HelperFunc.GetServerTime() then
            isLocked=true
        end
    elseif itemTableData.f_OpenType == 2 then
        if logicMgr.MapManager.getMapId() < itemTableData.f_OpenParm then
            isLocked=true
        end
    elseif itemTableData.f_OpenType == 3 then
        if this.getDataUpateTime(logicMgr.HeroManager.GetRoleInfo().createTime) + itemTableData.f_OpenParm * 24 * 60 * 60 > HelperFunc.GetServerTime() then
           isLocked=true
        end
    end
    if isLocked then
        serverData.activeState= SpecialDrawState.locked
    elseif serverData.param.selectDrawBuyTimes > 0 then
        serverData.activeState = SpecialDrawState.haveBought
    else
        --local day=GetTimeStampDayDis(serverData.startTime,HelperFunc.GetServerTime())
        local flag= this.IsActiveChallengeEnd(id)
        if not flag then
            if serverData.param.selectDrawTimes == 0 then
                serverData.redDots = true
                serverData.activeState = SpecialDrawState.startDraw
            elseif serverData.param.selectDrawTimes >= itemTableData.f_10DrawTime then
                serverData.activeState =SpecialDrawState.waitToBuy
            else
                serverData.redDots = true
                serverData.activeState = SpecialDrawState.continueDraw
            end
        else
            if serverData.param.selectDrawTimes<=0 then
                serverData.activeState=SpecialDrawState.canNotBuy
            else
                if canBuy then
                    serverData.redDots = true
                end
                serverData.activeState=SpecialDrawState.buy
            end
        end
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    return itemTableData, serverData;
end

function ActiveManager.getActiveSpecialDraw()
    local weight = -1
    local id = nil
    local activeState = 0
    local endTime = -1
    for k, v in pairs(EnumConst.ActiveShowType) do
        local activeIds = this.getActiveEntranceDataListByType(v);
        for i, v in ipairs(activeIds) do
            if v.activeType ~= nil and tonumber(v.activeType) == 7 then
                local localId = v.activeId;
                local _, serverData = this.disposeSpecialDrawSeverData(localId)
                local time = HelperFunc.GetServerTime()
                if not table.isNullOrEmpty(serverData) and serverData.isShow then
                    local state = serverData.activeState
                    local w = -10
                    if state == SpecialDrawState.buy then
                        w = 100
                    elseif state == SpecialDrawState.startDraw or state == SpecialDrawState.continueDraw then
                        w = 50
                    elseif state == SpecialDrawState.waitToBuy then
                        local cfg = G.dataTable["t_activity"][tostring(localId)];
                        endTime = serverData.startTime + (tonumber(cfg.f_ChallengeTime)) - time;
                        w = 25
                    end
                    if w > weight then
                        weight = w
                        id = localId
                        activeState = state
                    end
                end
            end
        end
    end
    return id, activeState, endTime
end

function ActiveManager.disposeCenterActivitySeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return ;
    end
    serverData.redDots = nil;
    local childActId = decodeJsonStrToTabel(itemTableData.f_ChildActivityId);
    local childActServerData = nil;
    local childTableData = nil;
    for i = 1, #childActId do
        childTableData, childActServerData = this.getActiveData(childActId[i]);
        if childActServerData ~= nil then
            if childActServerData.isShow then
                if childActServerData.redDots ~= nil and childActServerData.redDots then
                    serverData.redDots = true;
                    break;
                end
            end
        end
    end

    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    return itemTableData, serverData;
end

function ActiveManager.disposeActivityListTaskSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return ;
    end
    serverData.redDots = nil;
    local childModelName = decodeJsonStrToTabel(itemTableData.f_ModelName);
    local config = G.dataTable[tostring(childModelName[2])];
    local serverTaskData = serverData.param.taskMap;
    if serverTaskData ~= nil then
        for k, v in pairs(config) do
            if v.f_ActivityId == id then
                local taskData = serverTaskData[tostring(v.f_ActTaskId)];
                if taskData ~= nil and not taskData.rewarded then
                    if taskData.process >= v.f_Progress then
                        serverData.redDots = true;
                        break;
                    end
                end
            end
        end
    end

    if serverData.redDots == nil then
        local lotteryData = G.dataTable[tostring(childModelName[1])][tostring(id)];
        local lotteryReward = decodeJsonStrToTabel(lotteryData.f_LotteryReward);
        local isRewardEnd = false;
        local poolIndex = 0;
        if serverData.param ~= nil and serverData.param.poolIndex ~= nil then
            poolIndex = tonumber(serverData.param.poolIndex);
        end
        local rewardCount = #lotteryReward - 1;
        if poolIndex > rewardCount then
            isRewardEnd = true;
        elseif poolIndex == rewardCount then
            if serverData.param.poolRemainIndex == nil or #serverData.param.poolRemainIndex < 1 then
                isRewardEnd = true;
            end
        end
        --判断奖励是否领取完
        if not isRewardEnd then
            local costItem = decodeJsonStrToTabel(lotteryData.f_LotteryCost);
            local num = 0;
            for i = 1, #costItem do
                local haveNum = tonumber(logicMgr.ItemManager.getBagNumByTableID(costItem[i][1]));
                if haveNum >= tonumber(costItem[i][2]) then
                    num = num + 1;
                end
            end
            if num == #costItem then
                serverData.redDots = true;
            end
        end
    end

    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    return itemTableData, serverData;
end

function ActiveManager.disposeActivityListExchangeSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return ;
    end
    serverData.redDots = nil;
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    
    if not ActiveManager.GetExchangeRedDotState() then
        if serverData.isShow then
            local endTime = serverData.drawEndTime - HelperFunc.GetServerTime()
            if endTime > 0 and endTime < (2 * 24 * 3600) then
                local childActId = decodeJsonStrToTabel(itemTableData.f_CostItemId);
                local num = 0;
                for i = 1, #childActId do
                    local haveNum = logicMgr.ItemManager.getBagNumByTableID(childActId[i]);
                    if haveNum > 0 then
                        num = num + 1;
                    end
                end
                if num == #childActId then
                    serverData.redDots = true;
                end
            end
        end
    else
        serverData.redDots = false
    end
    
    return itemTableData, serverData;
end

function ActiveManager.disposeUIActivityListShopSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return ;
    end

    serverData.redDots = nil;
    local data = G.dataTable[tostring(itemTableData.f_ItemTableName)];
    local serverBuyCountData = serverData.param.buyCountMap;
    if serverBuyCountData ~= nil then
        for k,v in pairs(data) do
            if v.f_ActivityId == id and tonumber(v.f_RefreshType) == 2 and tonumber(v.f_Price) == 0 then
                --判断小红点
                local buyCountData = serverBuyCountData[tostring(v.f_ItemId)];
                if buyCountData == nil then
                    serverData.redDots = true;
                else
                    if tonumber(buyCountData) < v.f_Limit then
                        serverData.redDots = true;
                    end
                end
            end
        end
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    return itemTableData, serverData;
end

function ActiveManager.disposeTotalRechargeSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end

    serverData.redDots = nil;
    local data = G.dataTable[tostring(itemTableData.f_ItemTableName)];
    local itemData = {};
    for k,v in pairs(data) do
        if tonumber(v.f_ActivityId) == tonumber(id)  then
            table.insert(itemData, v);
        end
    end
    table.sort(itemData, function(a, b)
        return a.f_Order < b.f_Order;
    end);

    serverData.itemData = itemData;
    local price = 0;
    if serverData.param ~= nil and serverData.param.totalPay ~= nil then
        price = tonumber(serverData.param.totalPay);
    end
    serverData.num = price;
    local rewardedSet;
    if serverData.param ~= nil and serverData.param.rewardedSet ~= nil then
        rewardedSet = {};
        local serverData = serverData.param.rewardedSet;
        for i = 1, #serverData do
            local serverItemData = {};
            serverItemData.rewarded = true;
            rewardedSet[tostring(serverData[i])] = serverItemData;
        end
    end
    serverData.rewardedSet = rewardedSet;
    local config;
    local isGetAll = false;
    if rewardedSet ~= nil then
        local maxNum = #itemData;
        for i = 1, maxNum do
            config = itemData[i];
            local buyCountData = rewardedSet[tostring(config.f_ItemId)];
            if i == maxNum and buyCountData ~= nil and buyCountData.rewarded then
                isGetAll = true;
                break;
            end
            if buyCountData == nil or (not buyCountData.rewarded) then
                break;
            end
        end
    else
        config = itemData[1];
    end
    serverData.itemId = config.f_ItemId;
    if isGetAll then
        serverData.state = 2;
    else
        if price >= tonumber(config.f_Price) then
            serverData.state = 1;
            serverData.redDots = true;
        else
            serverData.state = 0;
        end
    end

    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    return itemTableData, serverData;
end

function ActiveManager.TempDessertServerData()
    for k, v in pairs(EnumConst.ActiveShowType) do
        if v == EnumConst.ActiveShowType.ActiveCenter or v == EnumConst.ActiveShowType.PeriodicActivities then
            local activeBtnTab = this.getActiveEntranceDataListByType(v);
            local tableData, itemTableData;
            for i = 1, #activeBtnTab do
                local type = tonumber(activeBtnTab[i].activeType);
                local activeId = activeBtnTab[i].activeId;
                if type == 15 then
                    tableData = this.getActiveTableList(activeId);
                    if tableData == nil then
                        return;
                    end
                    local modelTableData = {};
                    if tableData.f_ModelName ~= "" then
                        modelTableData = G.dataTable[tableData.f_ModelName];
                    end
                    itemTableData = modelTableData[tostring(activeId)];
                    if itemTableData ~= nil then
                        local temp = os.date("*t", math.floor(HelperFunc.GetServerTime()));
                        local serverHour = tonumber(temp.hour);
                        local lastTime = decodeJsonStrToTabel(itemTableData.f_LastTime)
                        for i = 1, #lastTime do
                            local startTime = tonumber(lastTime[i][1]);
                            local endTime = tonumber(lastTime[i][2]);
                            if serverHour == startTime or serverHour == endTime then
                                FireEvent(Config.EventType.Fresh_Active);
                                return;
                            end
                        end
                    end
                end
            end
        end
    end
end

function ActiveManager.disposeDessertSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end
    serverData.redDots = nil;
    serverData.status = {};
    -- 卫峰和无双PY一波之后，改需求了
    --[[
    local rewardNum = 0;
    if serverData.param.data ~= nil then
        local localData = serverData.param.data;
        for k,v in pairs(localData) do
            serverData.status[v] = 2;
        end
    end
    local temp = os.date("*t", math.floor(HelperFunc.GetServerTime()));
    local serverHour = tonumber(temp.hour);
    local lastTime = decodeJsonStrToTabel(itemTableData.f_LastTime)
    for i = 1, #lastTime do
        local startTime = tonumber(lastTime[i][1]);
        local endTime = tonumber(lastTime[i][2]);
        if serverHour >= 5 and serverHour < startTime then
            serverData.status[i] = 0;
        elseif serverHour >= startTime and serverHour < endTime then
            if serverData.status[i] == nil or serverData.status[i] ~= 2 then
                serverData.status[i] = 1;
                rewardNum = rewardNum + 1;
            end
        else
            if serverData.status[i] == nil or serverData.status[i] ~= 2 then
                serverData.status[i] = 3;
            end
        end
    end
    if rewardNum > 0 then
        serverData.redDots = true;
    end
    --]]
    if serverData.param.rewarded == nil then
        serverData.status[1] = 1;
        serverData.redDots = true;
    else
        if serverData.param.rewarded then
            serverData.status[1] = 2;
        else
            serverData.status[1] = 1;
            serverData.redDots = true;
        end
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    return itemTableData, serverData;
end

function ActiveManager.disposeSealCrystalSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return ;
    end
    serverData.redDots = nil;
    serverData.status = {};
    local puzzleNum = 0;
    if serverData.param.puzzle ~= nil then
        local localPuzzle = serverData.param.puzzle;
        for k, v in pairs(localPuzzle) do
            serverData.status[v] = 1;
            puzzleNum = puzzleNum + 1;
        end
    end
    serverData.puzzleNum = puzzleNum;

    local serverTime = HelperFunc.GetServerTime();
    local costNum = logicMgr.ItemManager.getBagNumByTableID(itemTableData.f_CostItemId);
    local crystalNum = tonumber(itemTableData.f_CrystalNum);
    local sealNum = tonumber(itemTableData.f_SealNum);
    local delayTime = tonumber(G.dataTable["t_global"]["384"].f_int_value);
    local rewardNum = 0;
    serverData.crystaTime = {};
    if serverData.param.crystalMap ~= nil then
        local localCrystal = serverData.param.crystalMap;
        for key, value in pairs(localCrystal) do
            local crystalTime = tonumber(value);
            if crystalTime > 0 then
                crystalTime = (tonumber(value) + delayTime) * 0.001;
                if serverTime < crystalTime then
                    crystalNum = crystalNum - 1;
                elseif serverTime >= crystalTime then
                    crystalNum = crystalNum - 1;
                    rewardNum = rewardNum + 1;
                end
            end
            serverData.crystaTime[tostring(key)] = crystalTime;
        end
    end

    if rewardNum > 0 or (crystalNum > 0 and costNum > 0 and puzzleNum < sealNum) then
        serverData.redDots = true;
    end
    serverData.crystalNum = crystalNum;
    if puzzleNum >= sealNum then
        serverData.crystalNum = -1;
    end

    local sealCrystalCfg = G.dataTable["t_sealcrystal"];
    local sealCrystalCfgNum = 0;
    local cfgId = 0;
    for k, v in pairs(sealCrystalCfg) do
        sealCrystalCfgNum = sealCrystalCfgNum + 1;
        if puzzleNum >= tonumber(v.f_RewardCount) then
            if cfgId < v.f_CrystalBoxID then
                cfgId = v.f_CrystalBoxID;
            end
        end
    end
    serverData.serverRewards = {};
    if serverData.param.rewards ~= nil then
        local rewards = serverData.param.rewards;
        for rk, rv in pairs(rewards) do
            serverData.serverRewards[tonumber(rv)] = 1;
        end
    end
    serverData.rewardId = 0;
    for i = 1, cfgId do
        if serverData.serverRewards[i] == nil then
            serverData.redDots = true;
            serverData.rewardId = i;
            break;
        end
    end
    if cfgId == sealCrystalCfgNum and serverData.rewardId == 0 then
        serverData.rewardId = -1;
    end

    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
        this.addActivityBuff(id, EnumConst.EcoBuffType.SealCrystalActivity, itemTableData, serverData)
    end

    return itemTableData, serverData;
end

function ActiveManager.addActivityBuff(id, buffType, itemTableData, serverData)
    if serverData == nil or itemTableData == nil or not serverData.isShow then
        return ;
    end
    if this.ecoBuffUtimeMap[id] == nil and itemTableData.f_EcoBuff ~= nil and itemTableData.f_EcoBuff ~= "" then
        local challengeTime = serverData.drawEndTime;
        if itemTableData.f_OutputTime ~= nil and itemTableData.f_OutputTime ~= "" and tonumber(itemTableData.f_OutputTime) > 0 then
            challengeTime = serverData.startTime + tonumber(itemTableData.f_OutputTime);
        else
            local cfg = G.dataTable["t_activity"][tostring(id)];
            if cfg ~= nil and cfg.f_ChallengeTime ~= nil and cfg.f_ChallengeTime > 0 then
                challengeTime = serverData.startTime + (tonumber(cfg.f_ChallengeTime));
            end
        end
        if challengeTime > serverData.drawEndTime then
            challengeTime = serverData.drawEndTime;
        end
        if challengeTime > HelperFunc.GetServerTime() then
            logicMgr.EcoBuffManager.updateEcoBuff(buffType, decodeJsonStrToTabel(itemTableData.f_EcoBuff))
            this.ecoBuffUtimeMap[id] = utimer.timeCall(function()
                this.ecoBuffUtimeMap[id] = nil
                logicMgr.EcoBuffManager.updateEcoBuff(buffType, {});
            end, (challengeTime - HelperFunc.GetServerTime()) * 1000, 1);
        end
    end
end

function ActiveManager.disposeActivitySignInSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end
    serverData.redDots = nil;
    serverData.signRed = false;
    serverData.specialSignRed = false;

    local curDay = -1;
    local serverTime = HelperFunc.GetServerTime();
    if serverTime >= serverData.startTime then
        curDay = 1;
        local temp = os.date("*t", math.floor(serverData.startTime));
        local updateTime = G.dataTable["t_global"][tostring(35)].f_int_value;
        local toTime = 0;
        if temp.hour * 60 * 60  < updateTime then
            toTime = os.time({year = temp.year, month = temp.month, day = temp.day, hour = 5, min = 0, sec = 0});
        else
            temp = os.date("*t", (math.floor(serverData.startTime) + 86400));
            toTime = os.time({year = temp.year, month = temp.month, day = temp.day, hour = 5, min = 0, sec = 0});
        end
        local time = math.floor(serverTime) - toTime;
        if time > 0 then
            curDay = math.floor((time + 86400 -1) / 86400) + 1;
        end
    end
    serverData.curDay = curDay;

    local buy168 = false;
    if serverData.param.buy168 ~= nil then
        buy168 = serverData.param.buy168;
    end
    serverData.buy168 = buy168;

    local sign = {};
    if serverData.param.sign ~= nil then
        local serverSign = serverData.param.sign;
        for k,v in pairs(serverSign) do
            sign[v] = 1;
        end
    end

    local specialSign = {};
    if serverData.param.specialSign ~= nil then
        local serverSpecialSign = serverData.param.specialSign;
        for k,v in pairs(serverSpecialSign) do
            specialSign[v] = 1;
        end
    end

    local rewardIndex = -1;
    local fundItemConfig = {};
    local commonItems = {};
    local payItems = {};
    local fundTable = G.dataTable[itemTableData.f_ItemTableName];
    if fundTable ~= nil then
        for k, v in pairs(fundTable) do
            if tonumber(v.f_ActivityId) == tonumber(id) then
                v.statue = 0;
                local fundClass = tonumber(v.f_FundClass);
                if v.f_FundType == 0 then
                    if fundClass < curDay then
                        if sign[v.f_FundId] ~= nil then
                            v.statue = 2;
                        else
                            v.statue = 1;
                        end
                    elseif fundClass == curDay then
                        if sign[v.f_FundId] ~= nil then
                            v.statue = 2;
                        else
                            serverData.redDots = true;
                            serverData.signRed = true;
                            v.statue = 3;
                            rewardIndex = 0;
                        end
                    end
                    table.insert(commonItems, v);
                elseif v.f_FundType == 1 then
                    if buy168 then
                        if fundClass < curDay then
                            if specialSign[v.f_FundId] ~= nil then
                                v.statue = 2;
                            else
                                if rewardIndex == -1 then
                                    rewardIndex = 1;
                                end
                                serverData.redDots = true;
                                serverData.specialSignRed = true;
                                v.statue = 3;
                            end
                        elseif fundClass == curDay then
                            if specialSign[v.f_FundId] ~= nil then
                                v.statue = 2;
                            else
                                if rewardIndex == -1 then
                                    rewardIndex = 1;
                                end
                                serverData.redDots = true;
                                serverData.specialSignRed = true;
                                v.statue = 3;
                            end
                        end
                    end
                    table.insert(payItems, v);
                end
            end
        end
    end
    table.sort(commonItems, function(a, b)
        return a.f_FundClass < b.f_FundClass;
    end)
    table.sort(payItems, function(a, b)
        return a.f_FundClass < b.f_FundClass;
    end)
    fundItemConfig.commonItems = commonItems;
    fundItemConfig.payItems = payItems;

    serverData.rewardIndex = rewardIndex;

    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end

    return itemTableData, serverData, fundItemConfig;
end

function ActiveManager.disposeActivitySpTaskSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if itemTableData ~= nil then
        return itemTableData;
    end
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end
    serverData.redDots = nil;

    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end

    return itemTableData, serverData;
end

---心之试炼
function ActiveManager.disposeSoloChaosTestSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end
    serverData.param.hasReward = serverData.param.hasReward or {};
    serverData.param.harm = serverData.param.harm or 0;
    local _nowTime = this.getDataUpateTime(serverData.startTime, 0)
    if _nowTime <= logicMgr.LoginManager.getServerStartTime() then
        serverData.startDay = 0;
    else
        serverData.startDay = math.ceil((_nowTime - logicMgr.LoginManager.getServerStartTime())/(3600*24));
    end
    local nodeList = logicMgr.SoloChaosTestManager.getEndlessBossNode();
    serverData.param.state = 2;
    serverData.param.nowIndex = #nodeList + 1;
    for k, v in pairs(nodeList) do
        if serverData.param.harm >= v then
            if not logicMgr.CostManager.isExistInListByValue(serverData.param.hasReward, k) then
                serverData.param.nowIndex = k;
                serverData.param.needHarm = v;
                serverData.param.state = 1;
                break;
            end
        else
            serverData.param.nowIndex = k;
            serverData.param.needHarm = v;
            serverData.param.state = 0;
            break;
        end
    end
    serverData.redDots = this.getActiveOpenStatus(id, 1);
    if serverData.param.state == 1 then
        serverData.redDots = true;
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end

    return itemTableData, serverData, tableData;
end

---圣诞树
function ActiveManager.disposeChristmasTreeData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end
    serverData.redDots = this.getActiveOpenStatus(id, 1);
    serverData.param.point = serverData.param.point or 0;
    serverData.param.gotReward = serverData.param.gotReward or {};
    itemTableData.f_Award = decodeJsonStrToTabel(itemTableData.f_Award);
    itemTableData.f_Cost = decodeJsonStrToTabel(itemTableData.f_Cost);
    itemTableData.f_ClickCost = decodeJsonStrToTabel(itemTableData.f_ClickCost);
    serverData.param.itemList = {};
    serverData.param.nowTime = 0;
    local lastCost = 0;
    for k, v in pairs(itemTableData.f_Cost) do
        local data = {};
        data.cost = v;
        data.award = itemTableData.f_Award[k] or {};
        if serverData.param.point >= v then
            data.progress = 100;
            if logicMgr.CostManager.isExistInListByValue(serverData.param.gotReward, k) then
                data.state = 2;
            else
                data.state = 1;
                serverData.redDots = true;
            end
            lastCost = v;
            serverData.param.nowTime = k;
        else
            data.state = 0;
            if lastCost >= 0 then
                data.progress = math.floor((serverData.param.point - lastCost) * 100 / (v - lastCost));
                serverData.param.nowTime = k - 1;
                lastCost = -1;
            else
                data.progress = 0;
            end
        end
        table.insert(serverData.param.itemList, data);
    end
    if logicMgr.ItemManager.getBagNumByTableID(itemTableData.f_ClickCost[1]) >= itemTableData.f_ClickCost[2] then
        serverData.redDots = true;
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
        this.addActivityBuff(id, EnumConst.EcoBuffType.ChristmasTreeActivity, itemTableData, serverData)
    end
    return itemTableData, serverData, tableData;
end

-- 转盘
function ActiveManager.disposeLuckyGuySeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end
    serverData.redDots = false;
    serverData.rechargeRed = 0;
    serverData.taskRed = 0;
    serverData.dayTaskRed = 0;
    local info = this.GetTurntableActivityInfo(id);
    if info == nil then
        info = {};
        info.todayTurnCount = 0;
        info.insureCount = 0;
        info.score = 0;
        info.awardPool = {};
        info.resetCount = 0;
    else
        local time = HelperFunc.GetServerTime();
        local challengeTimeCountDown = serverData.endTime - time;
        local cfg = G.dataTable["t_activity"][tostring(id)];
        if cfg ~= nil and cfg.f_ChallengeTime ~= nil and tonumber(cfg.f_ChallengeTime) > 0 then
            challengeTimeCountDown = serverData.startTime + tonumber(cfg.f_ChallengeTime) - time;
        end
        if challengeTimeCountDown > 0 then
            -- 判断任务可以领取
            local cfgs = dataTable.getDataTable("t_periodtask")
            for k, v in pairs(cfgs) do
                if tonumber(v.f_ActivityId) == tonumber(id) then
                    local turntableTask = tonumber(v.f_TurntableTask);
                    if turntableTask == 4 then
                        --每充值30元可获得
                        local count = math.floor(info.totalPay / v.f_Progress)
                        if count > info.recvCount then
                            serverData.redDots = true;
                            serverData.taskRed = 2;
                        end
                    else
                        local data = this.GetTurntableTaskData(id,v.f_ActTaskId);
                        if data and data.recvStatus == 0 and data.process >= v.f_Progress then
                            serverData.redDots = true;
                            if turntableTask == 1 then
                                serverData.rechargeRed = 2;
                            elseif turntableTask == 2 then
                                if tonumber(v.f_FunctionType) == 7 then
                                    serverData.dayTaskRed = 2;
                                else
                                    serverData.taskRed = 2;
                                end
                            end
                        end
                    end
                end
            end

            local modelCfg = dataTable.getDataTableByStringId(itemTableData.f_ItemTableName,id);
            if modelCfg ~= nil then
                if tonumber(info.todayTurnCount) < tonumber(modelCfg.f_DailyFreeTimes) then
                    serverData.redDots = true;
                end
            end
        end
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end

    return itemTableData, serverData, info;
end

--圣诞放烟花活动
function ActiveManager.disposeCelebrationData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id)
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end
    local data = G.dataTable[tostring(itemTableData.f_ItemTableName)][tostring(id)]
    if not (data and data.f_Reward and data.f_BigReward) then return end
    local cfgData = {}
    local itemData = {}                                         --奖励道具
    local commonItemList = decodeJsonStrToTabel(data.f_Reward)  --普通奖励
    local freeTimesPerDay = data.f_Tims or 0                    --每日免费次数
    local todayCount = serverData.param.dayFireWorkTimes or 0   --今日燃放烟花次数
    local repairConsume = data.f_RepairConsume or 0             --每次签到消耗红魔石
    local specialItemLst = decodeJsonStrToTabel(data.f_BigReward)  --大奖奖池
    local specialItemBagId = data.f_BagId                       --大奖奖池对应的T_OptionItem的id
    local mustGetSpecialCount = data.f_Num or 1                 --配置获得大奖是在第几次

    local totalCount = serverData.param.totalFireWorkTimes or 0
    local openDay = logicMgr.ActiveManager.getActiveBeginDay(serverData.startTime)  --活动第几天
    local chooseSpecialItemIdx = serverData.param.selectReward   --选择的大奖index

    itemData["specialList"] = specialItemLst or {}
    itemData["special"] = specialItemLst[chooseSpecialItemIdx] or {}
    this.saveCelebrationBigAwardData(chooseSpecialItemIdx)
    itemData["common"] = commonItemList

    cfgData.activeId = id
    cfgData.itemData = itemData
    cfgData.freeTimesPerDay = freeTimesPerDay
    cfgData.repairConsume = repairConsume
    cfgData.specialItemBagId = specialItemBagId
    cfgData.mustGetSpecialCount = mustGetSpecialCount
    serverData.todayCount = todayCount
    serverData.redDots = false
    serverData.openDay = openDay
    serverData.totalCount = totalCount
    serverData.gotReward = serverData.param.gotReward or {}
    serverData.chooseSpecialItem = specialItemLst[chooseSpecialItemIdx] or {}
    if todayCount < cfgData.freeTimesPerDay then
        serverData.redDots = true
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    return cfgData, serverData
end

function ActiveManager.disposeActivityFreeData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id)
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end
    serverData.redDots = false;
    serverData.itemState = {};
    serverData.itemId = 0;
    local giftStatus = serverData.param.giftStatus or {};
    for k, v in pairs(giftStatus) do
        serverData.itemState[tostring(k)] = tonumber(v);
    end
    local challengeCountDown = serverData.endTime;
    local cfg = G.dataTable["t_activity"][tostring(id)];
    if cfg ~= nil and cfg.f_ChallengeTime ~= nil and tonumber(cfg.f_ChallengeTime) > 0 then
        challengeCountDown = serverData.startTime + tonumber(cfg.f_ChallengeTime);
    end
    if HelperFunc.GetServerTime() > challengeCountDown then
        for k, v in pairs(serverData.itemState) do
            if tonumber(v) == 1 then
                serverData.redDots = true;
                serverData.itemId = tonumber(k);
                break;
            end
        end
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    return itemTableData, serverData
end

-- 活动战令
function ActiveManager.disposeActivityBattlePass(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id)
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end
    serverData.redDots = false;
    serverData.itemList = {};
    serverData.itemId = 0;
    serverData.param.nowDay = this.getActiveBeginDay(serverData.startTime);
    local nowDay = serverData.param.nowDay;
    this._data = dataTable.getDataTable(itemTableData.f_ItemTableName);
    for k, v in pairs(this._data) do
        if v.f_BelongActiveId == id then
            v.state = {};
            if v.f_Day <= nowDay then
                if logicMgr.CostManager.isExistInListByValue(serverData.param.frees, v.f_Day) then
                    v.state[1] = 2;
                else
                    v.state[1] = 1;
                    serverData.redDots = true;
                end
                if serverData.param.recharged then
                    if logicMgr.CostManager.isExistInListByValue(serverData.param.recharges, v.f_Day) then
                        v.state[2] = 2;
                    else
                        v.state[2] = 1;
                        serverData.redDots = true;
                    end
                else
                    v.state[2] = 3;
                end
            else
                v.state[1] = 0;
                v.state[2] = 0;
            end
            table.insert(serverData.itemList, v);
        end
    end
    table.sort(serverData.itemList, function (a, b)
        return a.f_Day < b.f_Day;
    end);
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    return itemTableData, serverData;
end

--祈愿星牌活动
function ActiveManager.disposeActivityCardServerData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id)
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end
    serverData.redDots = false;
    serverData.taskRed = 0;
    if this._activityCardTaskCfg == nil then
        this._activityCardTaskCfg = {};
    end
    local taskItems = {};
    if this._activityCardTaskCfg[tostring(id)] == nil then
        local cfgs = dataTable.getDataTable("t_periodtask");
        for k, v in pairs(cfgs) do
            if tonumber(v.f_ActivityId) == tonumber(id) then
                table.insert(taskItems, v);
            end
        end
        this._activityCardTaskCfg[tostring(id)] = taskItems;
    else
        taskItems = this._activityCardTaskCfg[tostring(id)];
    end

    local totalPay = serverData.param.totalPay or 0;
    serverData.param.recvCount = 0;
    serverData.cardIndexs = {};
    local accStarCards = serverData.param.accStarCards or {};
    for k,v in pairs(accStarCards) do
        serverData.cardIndexs[tostring(v)] = k;
    end
    if serverData.param.rewardBigNumber == nil then
        serverData.param.rewardBigNumber = {};
    end
    if serverData.param.freeCount == nil then
        serverData.param.freeCount = 0;
    end
    if serverData.param.freeCount == 1 then
        serverData.redDots = true;
    end
    local serverTaskData = serverData.param.recvRewardCount or {};
    for k,v in pairs(taskItems) do
        local turntableTask = tonumber(v.f_TurntableTask);
        local taskData = serverTaskData[tostring(v.f_ActTaskId)];
        if turntableTask == 4 then
            --每充值30元可获得
            local bigNum = tonumber(v.f_BigNum);
            local count = math.floor(totalPay / v.f_Progress)
            local recvCount = 0;
            if taskData ~= nil then
                recvCount = taskData.recvCount;
            end
            serverData.param.recvCount = recvCount;
            if count > recvCount and (bigNum < 1 or recvCount < bigNum) then
                serverData.redDots = true;
                serverData.taskRed = 2;
            end
        else
            if taskData and taskData.recvCount == 0 and taskData.process >= v.f_Progress then
                serverData.redDots = true;
                serverData.taskRed = 2;
            end
        end
    end
    serverData.taskItems = taskItems;
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
    end
    return itemTableData, serverData;
end

function ActiveManager.disposeDivineInspirationData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id)
    if serverData == nil or tableData == nil or itemTableData == nil then
        return
    end
    serverData.redDots = false
    logicMgr.DivineInspirationManager.SetBoxReceivedList(serverData.param.tabRewards)   --设置已领取的章节奖励
    --logicMgr.DivineInspirationManager.SetCompleteMap(serverData.param.labelTypeCount) --设置各个任务组已完成的数量
    logicMgr.DivineInspirationManager.SetTaskList(serverData.param.taskMap)             --设置任务完成情况
    logicMgr.DivineInspirationManager.SetMyRankScore(serverData.param.score)            --设置自己当前排行榜积分
    logicMgr.DivineInspirationManager.SetMyTaskScore(serverData.param.taskScore)        --设置自己当前任务积分
    for i= 1,4 do
        local isShowRed = logicMgr.DivineInspirationManager.CheckShowRed(i)
        if isShowRed then
            serverData.redDots = true
        end
    end
    return itemTableData, serverData
end

function ActiveManager.disposeDivineInspirationGiftData(id)
    local tableData, modelTableData, serverData = this.getActiveInitialDataById(id)
    if tableData == nil or serverData == nil then
        return
    end
    serverData.redDots = false
    serverData.hasBuyMap = serverData.param.buyCountMap
    logicMgr.DivineInspirationManager.SetCostChaperId(serverData.param.chapterId)
    serverData.nextRefreshTime = serverData.param.nextRefreshTime
    return modelTableData, serverData
end

function ActiveManager.disposeDivineInspirationExchageData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id)
    if serverData == nil or tableData == nil or itemTableData == nil then
        return
    end
    serverData.redDots = false
    serverData.hasBuyMap = serverData.param.buyCountMap
    serverData.nextRefreshTime = serverData.param.nextRefreshTime
    if logicMgr.DivineInspirationManager.CheckCostTabShowRed(id, 1) or logicMgr.DivineInspirationManager.CheckCostTabShowRed(id, 2) then
        serverData.redDots = true
    end
    return itemTableData, serverData
end

function ActiveManager.disposeBlindBoxData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id)
    if serverData == nil or tableData == nil or itemTableData == nil then
        return
    end
    serverData.redDots = false
    serverData.taskRedDots = false
    serverData.todayCount = serverData.param.number or 0
    serverData.taskSrvMap =  {}
    serverData.taskCfgList =  {}
    serverData.taskCfgMap =  {}
    serverData.previewRewardCfg =  {}
    local taskCfgData = dataTable.getDataTable("t_periodtask")
    if not this.blindBoxTaskCfgData then
        serverData.taskCfgCount = 0
        this.blindBoxTaskCfgData = {}
        for k,v in pairs(taskCfgData) do
            if toNumber(v.f_ActivityId) == tonumber(id) then
                serverData.taskCfgCount = serverData.taskCfgCount + 1
                this.blindBoxTaskCfgData[v.f_ActTaskId] = v
            end
        end
    end
    serverData.taskCfgMap = this.blindBoxTaskCfgData
    local previreRewardCfgData = dataTable.getDataTable("t_activitydrawsp")
    if not this.blindBoxPreviewReward then
        this.blindBoxPreviewReward = {}
        for k,v in pairs(previreRewardCfgData) do
            if v.f_ActivityId == tonumber(id) then
                table.insert(this.blindBoxPreviewReward, v)
            end
        end
        table.sort(this.blindBoxPreviewReward, function(a,b) return a.f_ActivitydrawspId < b.f_ActivitydrawspId end)
    end
    serverData.previewRewardCfg = this.blindBoxPreviewReward
    for k,v in pairs(serverData.param.recvRewardCount) do
        local oneTaskCfgData = this.blindBoxTaskCfgData[v.taskId]
        if oneTaskCfgData then
            if v.process >= oneTaskCfgData.f_Progress and v.recvCount < 1 then
                serverData.redDots = true
                serverData.taskRedDots = true
            end
        end
        serverData.taskSrvMap[v.taskId] = v
    end
    local costItemId = tonumber(G.dataTable[tostring(tableData["f_ModelName"])][tostring(id)].f_DrawConsume[1]) or 1
    local haveNum = logicMgr.ItemManager.getCurrencyCountByModelId(costItemId)
    if haveNum > 0 then
        serverData.redDots = true
    end
    --if not (serverData.taskCfgList and #serverData.taskCfgList > 0) then
    for k,v in pairs(taskCfgData) do
        if toNumber(v.f_ActivityId) == tonumber(id) then
            local serveData = serverData.taskSrvMap[v.f_ActTaskId]
            v.state = 1 --0,可领取 1,前往 2,已领取
            if serveData then
                if serveData.process >= v.f_Progress then
                    if serveData.recvCount > 0 then
                        v.state = 2
                    else
                        v.state = 1
                    end
                end
            end
            table.insert(serverData.taskCfgList, v)
        end
    end
    table.sort(serverData.taskCfgList, function(a,b)
        if a.state ~= b.state then
            return a.state < b.state
        else
            return a.f_ActTaskId < b.f_ActTaskId
        end
    end)
    --end
    return tableData, serverData
end

-- 游玩活动
function ActiveManager.disposeActivityExplorSeverData(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil or tableData == nil or itemTableData == nil then
        return;
    end
    serverData.redDots = nil;
    local serverPosIndex = serverData.param.totalCount or 1;
    if serverPosIndex < 1 then
        serverPosIndex = 1;
    else
        serverPosIndex = serverPosIndex + 1;
    end
    serverData.serverPosIndex = serverPosIndex;
    local haveNum = logicMgr.ItemManager.getBagNumByTableID(tonumber(itemTableData.f_CostId));
    if haveNum > 0 then
        serverData.redDots = true;
    end
    local taskMap = serverData.param.taskMap or {};
    local taskData = {};
    for k, v in pairs(taskMap) do
        local item = {};
        item.process = v.process;
        item.recvStatus = v.rewarded and 1 or 0;
        taskData[tostring(k)] = item;
    end
    if this.activityExplorTaskData[id] == nil then
        this.activityExplorTaskData[id] = {};
        local cfgs = dataTable.getDataTable("t_periodtask");
        for k, v in pairs(cfgs) do
            if v.f_ActivityId == id then
                table.insert(this.activityExplorTaskData[id], v);
            end
        end
    end
    serverData.taskRed = false;
    for k, v in pairs(this.activityExplorTaskData[id]) do
        local data = taskData[tostring(v.f_ActTaskId)]
        if data and data.recvStatus == 0 and data.process >= v.f_Progress then
            serverData.redDots = true;
            serverData.taskRed = true;
            break;
        end
    end
    serverData.taskData = taskData;
    serverData.explorTaskData = this.activityExplorTaskData[id];

    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or serverData.drawEndTime > 0 and HelperFunc.GetServerTime() > serverData.drawEndTime then
        serverData.isShow = false;
    else
        serverData.isShow = true;
        local configg = G.dataTable["t_activityexplor"][tostring(id)]
        this.addActivityBuff(id, EnumConst.EcoBuffType.ExplorActivity, configg, serverData)
    end
    return itemTableData, serverData;
end

--维护游玩活动数据
function ActiveManager.updateActivityExplorSeverData(id, totalCount)
    local serverData = this.activeServerDataList[tostring(id)];
    if serverData ~= nil then
        serverData.param.totalCount = totalCount;
    end
    this.activeServerDataList[tostring(id)] = serverData;
end
--游玩活动排行榜数据
function ActiveManager.updateActivityExplorRankData(msg)
    local actId = msg.activityId;
    local data = this.activityExplorRankData[tostring(actId)];
    if data == nil or tonumber(data.rankVersion) ~= tonumber(msg.rankVersion) then
        data = {};
        data.rankList = msg.rankList;
        data.selfRank = tonumber(msg.selfRank);
        data.selfOrderVal = tonumber(msg.selfOrderVal);
        data.rankVersion = msg.rankVersion;
        this.activityExplorRankData[tostring(actId)] = data;
    end
end
function ActiveManager.GetActivityExplorRankInfo(activityId)
    local data = this.activityExplorRankData[tostring(activityId)];
    return data or nil;
end
function ActiveManager.updateActivityExplorMyRank(id, score)
    local data = this.activityExplorRankData[tostring(id)];
    if data ~= nil then
        data.selfOrderVal = tonumber(score);
        this.activityExplorRankData[tostring(id)] = data;
    end
end
function ActiveManager.updateActivityExplorTask(id, taskList)
    local serverData = this.activeServerDataList[tostring(id)];
    if serverData ~= nil then
        local taskMap = serverData.param.taskMap;
        for k, v in pairs(taskList) do
            local item = {};
            item.process = v.process;
            item.rewarded = v.recvStatus == 1;
            taskMap[tostring(v.taskId)] = item;
        end
        serverData.param.taskMap = taskMap;
    end
    this.activeServerDataList[tostring(id)] = serverData;
end
function ActiveManager.updateActivityExplorTask2(id, taskId)
    local serverData = this.activeServerDataList[tostring(id)];
    if serverData ~= nil then
        local taskMap = serverData.param.taskMap;
        for k, v in pairs(taskMap) do
            if tostring(k) == tostring(taskId) then
                v.rewarded = true;
                taskMap[tostring(taskId)] = v;
                break;
            end
        end
        serverData.param.taskMap = taskMap;
    end
    this.activeServerDataList[tostring(id)] = serverData;
end

function ActiveManager.saveCelebrationBigAwardData(idx)
    local actModelTableInfo = G.dataTable["t_activityfullyueqing"][tostring(21001)]
    if actModelTableInfo then
        local bigAwardLst = decodeJsonStrToTabel(actModelTableInfo.f_BigReward)
        if bigAwardLst then
            this.celebrationBigAward = bigAwardLst[idx]
        end
    end
end

function ActiveManager.getCelebrationBigAwardData()
    return this.celebrationBigAward
end

function ActiveManager.getCelebrationBigAwardIdx(itemId)
    local actModelTableInfo = G.dataTable["t_activityfullyueqing"][tostring(21001)]
    if actModelTableInfo then
        local bigAwardLst = decodeJsonStrToTabel(actModelTableInfo.f_BigReward)
        if bigAwardLst then
            for k,v in pairs(bigAwardLst) do
                if v[1] and v[1] == itemId then
                    return k
                end
            end
        end
    end
    return nil
end

--根据活动类型拿活动id列表
function ActiveManager.getActiveIdListByType(type, isIgnoreEnd)
    local data = {};
    for k, v in pairs(this.getActiveTableList()) do
        if v.f_ActivityType == type and (isIgnoreEnd or not this.IsActiveEnd(v.f_ActivityId)) then
            table.insert(data, v.f_ActivityId);
        end
    end
    return data;
end
--活动是否结束（活动不可完成也不可领取）
function ActiveManager.IsActiveEnd(id)
    local serverData = this.getActiveServerDataList(id);
    if serverData == nil then
        return true;
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or (serverData.drawEndTime > 0 and HelperFunc.GetServerTime() >= serverData.drawEndTime) then
        return true;
    end
    return false;
end

--活动是否挑战结束（活动不可完成但可领取）
function ActiveManager.IsActiveChallengeEnd(id)
    local tableData, itemTableData, serverData = this.getActiveInitialDataById(id);
    if serverData == nil then
        return true;
    end
    local challengeTime = serverData.drawEndTime;
    if itemTableData ~= nil and itemTableData.f_OutputTime ~= nil and itemTableData.f_OutputTime ~= "" and tonumber(itemTableData.f_OutputTime) > 0 then
        challengeTime = serverData.startTime + tonumber(itemTableData.f_OutputTime);
    else
        local cfg = G.dataTable["t_activity"][tostring(id)];
        if cfg ~= nil and cfg.f_ChallengeTime ~= nil and cfg.f_ChallengeTime > 0 then
            challengeTime = serverData.startTime + (tonumber(cfg.f_ChallengeTime));
        end
    end
    if challengeTime > serverData.drawEndTime then
        challengeTime = serverData.drawEndTime;
    end
    if HelperFunc.GetServerTime() < serverData.startTime or serverData.state ~= 1 or (challengeTime > 0 and HelperFunc.GetServerTime() > challengeTime) then
        return true;
    end
    return false;
end

--限时召唤活动，抽卡心愿单及定向需排除的英雄 (卫峰恶心玩家的恶心需求)
function ActiveManager.RemoveHeroIds()
    local heroIds = {};
    for k, v in pairs(EnumConst.ActiveShowType) do
        local activeBtnTab = this.getActiveEntranceDataListByType(v);
        for i = 1, #activeBtnTab do
            local type = tonumber(activeBtnTab[i].activeType);
            local activeId = activeBtnTab[i].activeId;
            if type == 20 then
                local activityDraw = G.dataTable["t_activitydraw"][tostring(activeId)]
                if activityDraw ~= nil and activityDraw.f_RemoveNewHero ~= nil and activityDraw.f_RemoveNewHero ~= "" then
                    local removeNewHero = activityDraw.f_RemoveNewHero;
                    for k, v in pairs(removeNewHero) do
                        table.insert(heroIds, v);
                    end
                end
            end
        end
    end
    return heroIds;
end

---------------------------------------------------- 登陆弹窗类 ----- 开始---------------------
--- 只做活动登陆弹窗展示，其他弹窗需要重新开发，活动弹窗可以当做一个整体弹窗，不影响后续开发通用登陆弹窗。
--糊脸公告点击前往后续弹框不弹了
function ActiveManager.resetActivePopUpTips()
    this.isNeedShowPopUpTips = false;
    this.waitPopTips = {};
end

function ActiveManager.startActivePopUpTips()
    if logicMgr.GuideMgr.IsGuiding() then
        this.isNeedShowPopUpTips = false;
        this.waitPopTips = {}
        logicMgr.CostManager.startActivePopUpTips();
        return;
    end
    if this.isNeedShowPopUpTips == nil or this.isNeedShowPopUpTips then
        this.isNeedShowPopUpTips = false;
        if this.waitPopTips ~= nil and #this.waitPopTips > 0 then
            table.sort(this.waitPopTips, function(a, b)
                return a.order < b.order;
            end);
            this.showPopUpTips();
        else
            logicMgr.CostManager.startActivePopUpTips();
            this.waitPopTips = {};
        end
    else
        logicMgr.CostManager.startActivePopUpTips();
    end
end

--添加一个进入弹窗
function ActiveManager.addPopTipsById(id)
    if this.isNeedShowPopUpTips == true then
        local itemTableData, serverData = this.getActiveData(id);
        itemTableData = this.getActiveTableList(id);
        if itemTableData ~= nil and serverData ~= nil and serverData.redDots and itemTableData.f_LoginDupm ~= 0 then
            this.addPopUpTips(itemTableData.f_InterSurface, id, itemTableData.f_LoginDupm);
        end
    end
end

function ActiveManager.addPopUpTips(uiName, id, order)
    if this.isNeedShowPopUpTips == false then
        this.waitPopTips = {}
        return;
    end
    if this.waitPopTips == nil then
        this.waitPopTips = {};
    end
    for k, v in pairs(this.waitPopTips) do
        if v.activeId == id then
            return;
        end
    end
    local data = {};
    data.uiName = uiName;
    data.activeId = id;
    data.order = order;
    table.insert(this.waitPopTips, data);
end

function ActiveManager.showPopUpTips()
    if this.waitPopTips ~= nil and #this.waitPopTips > 0 then
        local data = this.waitPopTips[1];
        table.remove(this.waitPopTips, 1);
        local name = PanelNames[data.uiName];
        if name == nil then
            this.showPopUpTips()
            return;
        end
        if not isOpenUI(name) then
            showUI(name, nil, data.activeId);
        end
    else
        logicMgr.CostManager.startActivePopUpTips();
    end
end
---------------------------------------------------- 登陆弹窗类 ----- 结束---------------------
---------------------------------------------------- 连斩召唤 ----- 开始 ---------------------
---
function ActiveManager.resSelectDrawRefresh(msg)
    if isOpenUI(PanelNames.UIDrawResult) then
        UIDrawResult.refreshCard(msg.items, 1, msg.activityId);
    else
        showUI(PanelNames.UIDrawResult, msg.items, 1, msg.activityId);
    end
end
---
function ActiveManager.resSelectDrawBuy(msg)
    if isOpenUI(PanelNames.UIDrawResult) then
        UIDrawResult.refreshCard(msg.selectDrawBox.items, 3, msg.activityId);
    else
        showUI(PanelNames.UIDrawResult, msg.selectDrawBox.items, 3, msg.activityId);
    end
end
---------------------------------------------------- 连斩召唤 ----- 结束 ---------------------
---监听等级变化
function ActiveManager.FreshLevelInfo()
    logicMgr.ActiveManager.updateActiveLimit();
end


function ActiveManager.Track_OnTaoHuaReward(id)
    TAManager.TrackByDictionary("activity_taohua_reward", {task_id = id})
end

function ActiveManager.Track_OnTaoHuaFinish(id)
    TAManager.TrackByDictionary("activity_taohua_finish", {task_id = id})
end

--设置兑换活动红点显示
function ActiveManager.ExchangeSetRedDot(show)
    SetPlayerPrefs("exchange_activity", show)
    FireEvent(Config.EventType.Fresh_Active);
end

function ActiveManager.GetExchangeRedDotState()
    local show = GetPlayerPrefs("exchange_activity") or 0
    return tonumber(show) == 1
end

return ActiveManager